<?php
	//TuấnNK add (20080617_10h):
	//Xử lý cập nhật lại category js:

	require_once 'core/Debug.php'; //System Debug...
	require_once 'core/config.php';//System Config...
	
	require_once ROOT_PATH.'core/CGlobal.php';
	require_once ROOT_PATH.'core/DB.php';
	
	//Khởi tạo các biến hệ thống:
	global $server_list;
	CGlobal::$my_server=$server_list;
	unset($server_list);
	
	if(MEMCACHE_ON)
	require_once ROOT_PATH.'core/AZMemcache.php';
	
	require_once ROOT_PATH.'core/AZLib.php';
	require_once ROOT_PATH.'core/AZArrCache.php';
	require_once ROOT_PATH.'core/System.php';
	require_once ROOT_PATH.'core/Url.php';
	
	// Disable ALL magic_quote
	set_magic_quotes_runtime(0);
	register_shutdown_function(array("DB","close"));
	
	$cat_file = ROOT_PATH."javascript/categories.js";
	
	AZLib::getCats();
	
	foreach(CGlobal::$allCategories as $cat){
		$header_eb[] =  array(
											'id' 	=> $cat['id'],
											'pid' 	=> $cat['parent_id'],
											'name' 	=> $cat['name'],
											'path' 	=> "c{$cat['id']}/".(($cat['parent_id'] && isset(CGlobal::$allCategories[$cat['parent_id']]))?CGlobal::$allCategories[$cat['parent_id']]['ebname']."-":"").$cat['ebname']);
	}
	
	$header_eb_str = "header_eb = ".json_encode($header_eb).";";
		
	file_put_contents($cat_file,$header_eb_str);
	
	echo $header_eb_str;
	echo "<br /><br /><br />Done!";
?>